package com.liugai.lgeachday.controller;

import com.liugai.lgeachday.request.Response;
import com.liugai.lgeachday.tool.FileHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController()
@RequestMapping(value = "/file", produces = { "application/json;charset=UTF-8" })
public class FileController {

    @Autowired
    private FileHandler fileHandler;

    @RequestMapping(value = "upload/image", method = RequestMethod.POST)
    public Response uploadImage(@RequestParam(value = "file") MultipartFile file, Model model, HttpServletRequest request) {
        return fileHandler.uploadImage(file);
    }

    @RequestMapping(value = "upload/images", method = RequestMethod.POST)
    public Response uploadImage(@RequestParam(value = "file") List<MultipartFile> files, Model model, HttpServletRequest request) {
        System.out.println(files);
        return fileHandler.uploadImages(files);
    }
}
